import ktor.KtorObjectsDataSource
import models.Component
import models.Computer
import models.CreateComponentRequest
import models.CreateComputerRequest

class ObjectsRepositoryImpl(
    private val dataSource: KtorObjectsDataSource
) : ObjectsRepository {
    override suspend fun getMyComputers(): Result<List<Computer>> {
        return dataSource.getMyComputers().checkNullAndGet()
    }

    override suspend fun getMyComponents(): Result<List<Component>> {
        return dataSource.getMyComponents().checkNullAndGet()
    }

    override suspend fun verifyComputer(id: Int): Result<Boolean> {
        return dataSource.verifyComputer(id).checkNull()
    }

    override suspend fun verifyComponent(id: Int): Result<Boolean> {
        return dataSource.verifyComponent(id).checkNull()
    }

    override suspend fun computerBySerialNumber(serialNumber: String): Result<Computer> {
        return dataSource.computerBySerialNumber(serialNumber).checkNullAndGet()
    }

    override suspend fun componentBySerialNumber(serialNumber: String): Result<Component> {
        return dataSource.componentBySerialNumber(serialNumber).checkNullAndGet()
    }

    override suspend fun getComponentTypes(): Result<List<String>> {
        return dataSource.getComponentTypes().checkNullAndGet()
    }

    override suspend fun getComputers(): Result<List<Computer>> {
        return dataSource.getComputers().checkNullAndGet()
    }

    override suspend fun getComponents(): Result<List<Component>> {
        return dataSource.getComponents().checkNullAndGet()
    }

    override suspend fun getComputer(id: Int): Result<Computer?> {
        return dataSource.getComputer(id).checkNullAndGet()
    }

    override suspend fun getComponent(id: Int): Result<Component?> {
        return dataSource.getComponent(id).checkNullAndGet()
    }

    override suspend fun getComputersByLocation(locationId: Int): Result<List<Computer>> {
        return dataSource.getComputersByLocation(locationId).checkNullAndGet()
    }

    override suspend fun getComponentsByLocation(locationId: Int): Result<List<Component>> {
        return dataSource.getComponentsByLocation(locationId).checkNullAndGet()
    }

    override suspend fun getComponentsByComputer(computerId: Int): Result<List<Component>> {
        return dataSource.getComponentsByComputer(computerId).checkNullAndGet()
    }

    override suspend fun createComputer(computer: CreateComputerRequest): Result<Int> {
        return dataSource.createComputer(computer).checkNullAndGet()
    }

    override suspend fun createComponent(component: CreateComponentRequest): Result<Int> {
        return dataSource.createComponent(component).checkNullAndGet()
    }

    override suspend fun updateComputer(id: Int, computer: CreateComputerRequest): Result<Boolean> {
        return dataSource.updateComputer(id, computer).checkNull()
    }

    override suspend fun updateComponent(
        id: Int,
        component: CreateComponentRequest
    ): Result<Boolean> {
        return dataSource.updateComponent(id, component).checkNull()
    }

    override suspend fun deleteComputer(id: Int): Result<Boolean> {
        return dataSource.deleteComputer(id).checkNull()
    }

    override suspend fun deleteComponent(id: Int): Result<Boolean> {
        return dataSource.deleteComponent(id).checkNull()
    }
}